% count_sequence
% Example: 
% s = count_sequence([0 0 0 1 1 1 0 0 0 1 1 0])
% s

function [ B ] = count_sequence( X )

B = [];
k=0;

for i=2:length(X)
    p1 = double(X(i-1));
    p2 = double(X(i));
    
    % from 0 to 1
    if (p1==0 && p2==1)
        k = i;
    elseif (p1 == 1 && i-1 ==1)
        k = i-1;
    elseif ((p1==1 && p2==0) || (p2==1 && i == length(X)))
          if (p2==1 && i == length(X)) 
              k = k-1;
          end;
          B = [B (i - k)];
    end

end
end



